using System.Windows;
using System.Windows.Controls;

namespace WPFPractice.UserControls.DynamicColumnTable
{
	public class TableEventHelper
	{
		#region 附加事件

		#region [附加事件] 单元格内容变化
		/// <summary>
		/// [附加事件] 单元格内容变化
		/// </summary>
		public static readonly RoutedEvent CellValueChangedEvent = EventManager.RegisterRoutedEvent("CellValueChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TableEventHelper));
		/// <summary>
		/// 添加 [附加事件] 单元格内容变化 [处理方法]
		/// </summary>
		public static void AddCellValueChangedHandler(DependencyObject dependencyObject, RoutedEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.AddHandler(CellValueChangedEvent, handler);
		}
		public static void RemoveCellValueChangedHandler(DependencyObject dependencyObject, RoutedEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.RemoveHandler(CellValueChangedEvent, handler);
		} 
		#endregion

		#region [附加事件] 内容区垂直滚动
		/// <summary>
		/// [附加事件] 内容区垂直滚动
		/// </summary>
		public static readonly RoutedEvent ContentVerticalScrolledEvent = EventManager.RegisterRoutedEvent("ContentVerticalScrolled", RoutingStrategy.Bubble, typeof(ScrolledEventHandler), typeof(TableEventHelper));
		/// <summary>
		/// 添加 [附加事件] 内容区垂直滚动 [处理方法]
		/// </summary>
		public static void AddContentVerticalScrolledHandler(DependencyObject dependencyObject, ScrolledEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.AddHandler(ContentVerticalScrolledEvent, handler);
		}
		public static void RemoveContentVerticalScrolledHandler(DependencyObject dependencyObject, ScrolledEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.RemoveHandler(ContentVerticalScrolledEvent, handler);
		} 
		#endregion

		#region [附加事件] 内容区水平滚动
		/// <summary>
		/// [附加事件] 内容区水平滚动
		/// </summary>
		public static readonly RoutedEvent ContentHorizontalScrolledEvent = EventManager.RegisterRoutedEvent("ContentHorizontalScrolled", RoutingStrategy.Bubble, typeof(ScrolledEventHandler), typeof(TableEventHelper));
		/// <summary>
		/// 添加 [附加事件] 内容区水平滚动 [处理方法]
		/// </summary>
		public static void AddContentHorizontalScrolledHandler(DependencyObject dependencyObject, ScrolledEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.AddHandler(ContentHorizontalScrolledEvent, handler);
		}
		public static void RemoveContentHorizontalScrolledHandler(DependencyObject dependencyObject, ScrolledEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.RemoveHandler(ContentHorizontalScrolledEvent, handler);
		}
		#endregion

		#region [附加事件] 列标题勾选改变
		/// <summary>
		/// [附加事件] 列标题勾选改变
		/// </summary>
		public static readonly RoutedEvent ColumnHeaderCheckChangedEvent = EventManager.RegisterRoutedEvent("ColumnHeaderCheckChanged", RoutingStrategy.Bubble, typeof(CheckChangedEventHandler), typeof(TableEventHelper));
		/// <summary>
		/// 添加 [附加事件] 列标题勾选改变 [处理方法]
		/// </summary>
		public static void AddColumnHeaderCheckChangedHandler(DependencyObject dependencyObject, CheckChangedEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.AddHandler(ColumnHeaderCheckChangedEvent, handler);
		}
		public static void RemoveColumnHeaderCheckChangedHandler(DependencyObject dependencyObject, CheckChangedEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.RemoveHandler(ColumnHeaderCheckChangedEvent, handler);
		}
		#endregion

		#region [附加事件] 行标题勾选改变
		/// <summary>
		/// [附加事件] 行标题勾选改变
		/// </summary>
		public static readonly RoutedEvent RowHeaderCheckChangedEvent = EventManager.RegisterRoutedEvent("RowHeaderCheckChanged", RoutingStrategy.Bubble, typeof(CheckChangedEventHandler), typeof(TableEventHelper));
		/// <summary>
		/// 添加 [附加事件] 行标题勾选改变 [处理方法]
		/// </summary>
		public static void AddRowHeaderCheckChangedHandler(DependencyObject dependencyObject, CheckChangedEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.AddHandler(RowHeaderCheckChangedEvent, handler);
		}
		public static void RemoveRowHeaderCheckChangedHandler(DependencyObject dependencyObject, CheckChangedEventHandler handler)
		{
			if(dependencyObject is not UIElement uiElement)
				return;
			uiElement.RemoveHandler(RowHeaderCheckChangedEvent, handler);
		}
		#endregion

		#endregion
	}

	/// <summary>
	/// 滚动事件处理方法委托
	/// </summary>
	public delegate void ScrolledEventHandler(object sender, ScrolledEventArgs e);

	/// <summary>
	/// 滚动事件参数
	/// </summary>
	public class ScrolledEventArgs : RoutedEventArgs
	{
		public ScrolledEventArgs () { }
		public ScrolledEventArgs(RoutedEvent routedEvent) : base(routedEvent) { }
		public ScrolledEventArgs(RoutedEvent routedEvent, object source) : base(routedEvent, source) { }

		/// <summary>
		/// 滚动偏移
		/// </summary>
		public double Offset { get; set; }

		/// <summary>
		/// 方向
		/// </summary>
		public Orientation? Direction { get; set; }
	}

	/// <summary>
	/// 勾选事件处理方法委托
	/// </summary>
	public delegate void CheckChangedEventHandler(object sender, CheckChangedEventArgs e);

	/// <summary>
	/// 勾选事件参数
	/// </summary>
	public class CheckChangedEventArgs : RoutedEventArgs
	{
		public CheckChangedEventArgs() { }
		public CheckChangedEventArgs(RoutedEvent routedEvent) : base(routedEvent) { }
		public CheckChangedEventArgs(RoutedEvent routedEvent, object source) : base(routedEvent, source) { }

		/// <summary>
		/// 标识
		/// </summary>
		public string Tag { get; set; }

		/// <summary>
		/// 是否被勾选
		/// </summary>
		public bool IsChecked { get; set; }
	}
}
